package com.wicket.okrframework.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wicket.okrframework.common.dto.FieldInfo;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrframework.base.service.MRoleTopBizSceneService;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.tools.StringUtils;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.dal.mapper.mbg.RoleTopBizSceneMapper;
import com.wicket.okrframework.dal.po.mbg.RoleMember;
import com.wicket.okrframework.dal.po.mbg.RoleTopBizScene;
import com.wicket.okrframework.base.service.dto.req.*;
//import com.wicket.okrframework.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MRoleTopBizSceneServiceImpl
  extends ServiceImpl<RoleTopBizSceneMapper, RoleTopBizScene>
  implements MRoleTopBizSceneService {

  @Autowired
  RoleTopBizSceneMapper roleTopBizSceneMapper;
/**
   * 1-2-08-01新增角色推荐到业务场景[5046]
   * gen by moon at 10/28/2022, 8:45:20 PM
   */
 @Trace(operationName = "1-2-08-01新增角色推荐到业务场景")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addRoleRecommendBizScene(RoleTopBizScene roleTopBizScene) {
     roleTopBizScene.setTopBizSceneRecordId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
roleTopBizScene.setIsArchive("FALSE");
roleTopBizScene.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
roleTopBizScene.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
roleTopBizScene.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
roleTopBizScene.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
roleTopBizScene.setIsValid("FALSE");
roleTopBizScene.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
roleTopBizScene.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(roleTopBizScene)){
        return roleTopBizScene.getTopBizSceneRecordId();
     }else {
        return "-1";
     }
    
  }
/**
   * 1-2-08-01修改角色推荐到业务场景[5047]
   * gen by moon at 10/28/2022, 8:45:20 PM
   */
 @Trace(operationName = "1-2-08-01修改角色推荐到业务场景")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updateRoleRecommendBizScene(RoleTopBizScene roleTopBizScene) {
     roleTopBizScene.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(roleTopBizScene!=null && roleTopBizScene.getSubjectLifeCycle()!=null && roleTopBizScene.getSubjectLifeCycle().equals("ARCHIVING")) {
              roleTopBizScene.setArchiveInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//ARCHIVE_CURRENT_INDUCTIONID
          }
roleTopBizScene.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(roleTopBizScene!=null && roleTopBizScene.getSubjectLifeCycle()!=null && roleTopBizScene.getSubjectLifeCycle().equals("ARCHIVING")) {
              roleTopBizScene.setArchiveTime(CommonFunctionHelper.getCurrentTime());//HISTORICAL_ARCHIVING
          }
        return super.updateById(roleTopBizScene);
  }
/**
   * 1-2-08-01删除角色推荐到业务场景[5048]
   * gen by moon at 10/28/2022, 8:45:21 PM
   */
 @Trace(operationName = "1-2-08-01删除角色推荐到业务场景")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  deleteRoleRecommendBizScene(String topBizSceneRecordId ) {
     
      return super.removeById(topBizSceneRecordId);
  }
/**
   * 1-2-08-01查询角色推荐到业务场景详情[5049]
   * gen by moon at 10/28/2022, 8:45:21 PM
   */
 @Trace(operationName = "1-2-08-01查询角色推荐到业务场景详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  RoleTopBizScene  queryRoleRecommendBizSceneDetail(QueryRoleRecommendBizSceneDetailReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<RoleTopBizScene> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<RoleTopBizScene> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                RoleTopBizScene retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 1-2-08-01查询角色推荐到业务场景列表[5050]
   * gen by moon at 10/28/2022, 8:45:22 PM
   */
 @Trace(operationName = "1-2-08-01查询角色推荐到业务场景列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<RoleTopBizScene>  queryRoleRecommendBizSceneList(QueryRoleRecommendBizSceneListReq reqDto) {
     
        try {
            QueryWrapper<RoleTopBizScene> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(RoleTopBizScene.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(RoleTopBizScene.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(RoleTopBizScene.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<RoleTopBizScene>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }

}

